package kz.kstu.website.util;

import java.util.Random;

/**
 * @author Filipp_Stankevich
 *         created: 6/24/11 6:20 PM
 */
public class StringUtil {

    private StringUtil() {
    }

    /***
     * Method for getting random string
     *
     * @param count count of letters
     * @param exclude letter to exclude from random string
     * @return random string
     */
    public static String getRandomString(int count, String exclude) {
        if (exclude == null) {
            exclude = "";
        }
        if (count <= 0) {
            throw new IllegalArgumentException("Character length must be > 0");
        }
        int start = ' ';
        int end = 'z' + 1;
        int num = end - start;
        StringBuffer buf = new StringBuffer();
        char c;
        Random random = new Random();
        while (count-- != 0) {
            c = (char) random.nextInt(num);
            if (Character.isLetterOrDigit(c) && exclude.indexOf((int) c) < 0) {
                buf.append(c);
            } else {
                count++;
            }
        }
        return buf.toString();
    }
}
